package com.zjc.agent.ai.config;

import com.zjc.agent.ai.service.AIFlightHelperService;
import com.zjc.agent.ai.tools.*;
import dev.langchain4j.mcp.McpToolProvider;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AIHelperServiceFactory {
    @Resource
    private OpenAiChatModel openAiChatModel;
    @Resource
    private StreamingChatModel streamingChatModel;

    @Resource
    private McpToolProvider mcpToolProvider;
    
    /**
     * 创建AIFlightHelperService：反射+动态代理
     */
    @Bean
    public AIFlightHelperService create() {
        // 会话记忆
        ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);
        // 构造AiServices
        return AiServices.builder(AIFlightHelperService.class)
                .chatModel(openAiChatModel)
                .toolProvider(mcpToolProvider)
                .streamingChatModel(streamingChatModel)
                .chatMemory(chatMemory)
                .chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
                .tools(new FlightTool(),new WeatherTool(),new TimeTool(),new PassengerTool(),new OrderTool())
                .build();
    }
}